import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_module/main.dart';

/// Create by kyluzoi
/// Date: 2021-08-16
///
/// Description:

class LoadingProgressDialog extends Dialog {
  final String text;

  LoadingProgressDialog({Key? key, required this.text}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return new Material(
      type: MaterialType.transparency,
      child: new Center(
        child: new SizedBox(
          width: 85,
          height: 85,
          child: new Container(
            decoration: ShapeDecoration(
              color: Color(0xcc414144),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(
                  Radius.circular(10),
                ),
              ),
            ),
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Theme(
                  data: ThemeData(cupertinoOverrideTheme: CupertinoThemeData(
                    brightness: Brightness.dark,
                  )),
                  child: CupertinoActivityIndicator(
                    radius: 16,
                  ),
                ),
                new Padding(
                  padding: const EdgeInsets.only(
                    top: 5,
                  ),
                  child: new Text(
                    text,
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 16,
                    ),
                  ),
                ),
              ],
            ),)
          ,
        )
        ,
      )
      ,
    );
  }

  //屏蔽物理返回键
  show({BuildContext? context}) {
    showDialog(
        context: context ?? AppGlobalKey.currentContext!,
        barrierDismissible: false, //点击边框外不消失
        builder: (_) =>
            WillPopScope(
              child: LoadingProgressDialog(text: text),
              onWillPop: () async {
                return false;
              },
            ));
  }

  disMiss({BuildContext? context}) {
    Navigator.of(context ?? AppGlobalKey.currentContext!).pop();
  }
}
